<template>
	<view id="canvasImg">
		<view class="ys">
			<view class="sharbox">
				<view class="title">
					我的邀请码 <u-icon class="icon" @click="copy(code)" name="file-text"></u-icon>
				</view>
				<view class="code">
					{{code}}
				</view>
				<view class="codeimg">
					<!-- #ifdef H5 -->
					<uqrcode ref="uqrcode" canvas-id="qrcode" :value="link" @longtap="save">
					</uqrcode>
					<!-- #endif -->
					<!-- #ifdef MP-WEIXIN -->
					<image :src="qrcode" mode="widthFix"></image>
					<!-- #endif -->
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		getMpQrcode
	} from "@/api/api.js"

	export default {
		data() {
			return {
				code: '',
				link: '',
				lineColor: 'black',
				slideValue: 50,
				handwriting: '',
				selectColor: 'black',
				color: '',
				width: '',
				height: '',
				base: '',
				websiteUrl: '',
				qrcode: ''
			}
		},
		onReady() {
			if (this.$refs.uqrcode) {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {}
				});
			}
		},
		async onLoad() {
			this.getMpQrcode()
		},
		methods: {
			getMpQrcode() {
				getMpQrcode().then(res => {
					if (res.code == 0) {
						this.code = res.data.code
						this.link = this.$config.websiteUrl + `pages/login/index?invite=${this.code}`
						this.qrcode = res.data.qrcode
					}
				})
			},
			saveImg() {
				var that = this
				that.$refs.uqrcode.save({
					success: res => {
						uni.$showMsg('保存成功')
					}
				});

			},

			copy(data) {
				uni.setClipboardData({
					data
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		min-height: 100vh;
		height: 100%;
		background: $uni-bg-color;
		background-size: 100% 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.baseimg {
		position: fixed;
		z-index: 1111;
		width: 80%;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		box-shadow: 0 0 10px #000;
		border-radius: 10px;
	}

	.myCanvas {
		position: fixed;
		z-index: -1;
		left: -100%;
	}

	.sharbox {
		width: 280px;
		padding: 18px 0 24px 0;
		background: linear-gradient(45deg, #ffffff33, #ffffffb3, #ffffff33);
		border-radius: 8px;
		display: flex;
		flex-direction: column;
		align-items: center;
		color: #000;
		font-size: 16px;
		padding-bottom: 40px;

		.title {
			display: flex;
			font-size: 15px;

			.icon {
				margin-left: 5px;
			}
		}

		.code {
			margin-top: 10px;
			font-weight: bold;
		}

		.down {
			margin: 15px 0;
		}

		.codeimg {
			width: 80%;
			margin-top: 10px;
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				width: 100%;
			}
		}

		.link {
			margin-top: 10px;
			width: 80%;
			word-break: break-all;
			font-size: 13px;
		}

	}
</style>